<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<title>用户</title>
<link rel="stylesheet" type="text/css" href="../easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../easyui/demo/demo.css">
<script type="text/javascript" src="../easyui/jquery.min.js"></script>
<script type="text/javascript" src="../easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../uploadjs/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="../uploadjs/jquery.fileupload.js"></script>
<script type="text/javascript" src="../js/auth.js"></script>
<script type="text/javascript" src="../js/sha1.js"></script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',border:false" style="height:100px;background:#B3DFDA;padding:10px">
<div style="float:right;clear:both;margin-top:15px;margin-right:20px">
	<a href="javascript:logout()">注销</a>
	</div>
	<h2>蛋糕商城Rust版</h2>
	<h3>从2025为公众服务</h3>
</div>
<div data-options="region:'west',split:true,title:'主菜单'" style="width:180px;padding:0px;">
<div onclick="window.location='../pages/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">主页</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../custpages/admin/index.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">蛋糕商城后台</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/goodses.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">商品</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/custorders.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">订单</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/paytypes.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">支付方式</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/statuses.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">状态</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/orderitems.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">订单项</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/goodstypes.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">类型</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/recommends.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">推荐</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/roles.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">角色</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/permissions.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">许可</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/users.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">用户</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/profile.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">用户资料</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkrolepermission.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接角色许可</div><div class="menu-icon icon-add"></div></div>
<div onclick="window.location='../pages/linkuserrole.html'" class="menu-item" style="height: 20px;"><div class="menu-text" style="height: 20px; line-height: 20px;">链接用户角色</div><div class="menu-icon icon-add"></div></div>
</div>
<div data-options="region:'east',split:true,collapsed:true,title:'属性'" style="width:250px;overflow: hidden">
</div>
<div data-options="region:'south',border:false" style="height:40px;background:#A9FACD;padding:10px;text-align: center">
	蛋糕商城
</div>
<div data-options="region:'center',title:'Rust语言通用代码生成器：莲花　生成结果'">
<div title="搜索面板" class="easyui-panel" style="width:1600px;height:200px">
<form id="ffsearch" method="post">
<table cellpadding="5">
<tr>
<td>用户名:</td><td><input  class='easyui-textbox' type='text' name='userName' id='userName' value='' data-options="required:false"/></td>
<td>活跃:</td><td><input  class='easyui-textbox' type='text' name='active' id='active' value='' data-options="required:false"/></td>
<td>名字:</td><td><input  class='easyui-textbox' type='text' name='firstName' id='firstName' value='' data-options="required:false"/></td>
<td>
		<select id="actionSelect" class='easyui-select' style="	width:90px;height:28px" onchange="toggleBtnShow(this.value)">
			<option value="1" selected>搜索</option>
			<option value="2">Excel过滤</option>
			<option value="3">PDF过滤</option>
		</select>
		</td><td>
		<div id="button-bar">
			<a href="#" class="easyui-linkbutton" style="display:block;width:110px;height:28px" data-options="iconCls:'icon-search'" onclick="searchUsersByFieldsByPage()">搜索</a>
			<a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterUsersExcel()">Excel过滤</a>
			<a href="#" class="easyui-linkbutton" style="display:none;width:110px;height:28px" data-options="iconCls:'icon-filter'" onclick="filterUsersPDF()"">PDF过滤</a>
		</div>
		</td><td>
			<a href="javascript:void(0)" class="easyui-linkbutton" style="width:80px" data-options="iconCls:'icon-clear'"  onclick="clearForm('ffsearch');toggleBtnShow(1);$('#actionSelect').val(1)">清除</a>
</td>
</tr>
<tr>
<td>姓:</td><td><input  class='easyui-textbox' type='text' name='lastName' id='lastName' value='' data-options="required:false"/></td>
<td>电子邮件:</td><td><input  class='easyui-textbox' type='text' name='email' id='email' value='' data-options="required:false"/></td>
<td>是否管理员:</td><td><input  class='easyui-textbox' type='text' name='isadmin' id='isadmin' value='' data-options="required:false"/></td>
<td></td><td colspan='3'></td>
</tr>
<tr>
<td>性别:</td><td><input  class='easyui-textbox' type='text' name='gender' id='gender' value='' data-options="required:false"/></td>
<td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td>
<td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td>
<td></td><td colspan='3'></td>
</tr>
<tr>
<td>描述:</td><td><input  class='easyui-textbox' type='text' name='description' id='description' value='' data-options="required:false"/></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td></td><td colspan='3'></td>
</tr>
</table>
</form>
</div>
<table id="dg" class="easyui-datagrid" title="用户清单" style="width:1600px;height:600px" data-options="singleSelect:false,url:'../controller/userController/searchUsersByFieldsByPage',queryParams:params,method:'post',pagination:true,toolbar:toolbar">
<thead>
<tr>
<th data-options="field:'id',checkbox:true">序号</th>
<th data-options="field:'userName',width:80">用户名</th>
<th data-options="field:'active',width:80">活跃</th>
<th data-options="field:'firstName',width:80">名字</th>
<th data-options="field:'lastName',width:80">姓</th>
<th data-options="field:'email',width:80">电子邮件</th>
<th data-options="field:'isadmin',width:80">是否管理员</th>
<th data-options="field:'gender',width:80">性别</th>
<th data-options="field:'address',width:80">地址</th>
<th data-options="field:'phone',width:80">电话</th>
<th data-options="field:'description',width:80">描述</th>
<th data-options="field:'photo',width:140,formatter:showUserPhotoImage">照片</th>
</tr>
</thead>
</table>
<div class="easyui-window" title="新增用户" id="waddUser" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ff" method="post">
<table cellpadding="5">
<tr><td>用户名:</td><td><input  class='easyui-textbox' type='text' name='userName' id='userName' value='' data-options="required:false"/></td></tr>
<tr><td>密码:</td><td><input  class='easyui-textbox' type='password' name='password' id='password' value='' data-options="required:false"/></td></tr>
<tr><td>确认密码:</td><td><input  class='easyui-textbox' type='password' name='confirmPassword' id='confirmPassword' value='' data-options="required:false"/></td></tr>
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='firstName' id='firstName' value='' data-options="required:false"/></td></tr>
<tr><td>姓:</td><td><input  class='easyui-textbox' type='text' name='lastName' id='lastName' value='' data-options="required:false"/></td></tr>
<tr><td>电子邮件:</td><td><input  class='easyui-textbox' type='text' name='email' id='email' value='' data-options="required:false"/></td></tr>
<tr><td>是否管理员:</td><td><input class='easyui-radio' type='radio' name='isadmin' id='isadmin' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='isadmin' id='isadmin' value='false'/>False</td></tr>
<tr><td>性别:</td><td><input  class='easyui-textbox' type='text' name='gender' id='gender' value='' data-options="required:false"/></td></tr>
<tr><td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td></tr>
<tr><td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><textarea  class='easyui-textarea' type='text' name='description' id='description' data-options="required:false" cols='20' rows='4'></textarea></td></tr>
<tr><td>照片:</td><td><img name='photo' id='photo' width='500px' src='../images/blank.jpg'><br>
<input id="addUserPhotoFileupload" type="file" name="files[]" data-url="../controller/userController/addUploadUserPhoto"><br></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addUser()">新增</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm('ff')">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#waddUser').window('close')">取消</a>
</div>
</div>
<div class="easyui-window" title="编辑用户" id="wupdateUser" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ffedit" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>用户名:</td><td><input  class='easyui-textbox' type='text' name='userName' id='userName' value='' data-options="required:false"/></td></tr>
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='firstName' id='firstName' value='' data-options="required:false"/></td></tr>
<tr><td>姓:</td><td><input  class='easyui-textbox' type='text' name='lastName' id='lastName' value='' data-options="required:false"/></td></tr>
<tr><td>电子邮件:</td><td><input  class='easyui-textbox' type='text' name='email' id='email' value='' data-options="required:false"/></td></tr>
<tr><td>是否管理员:</td><td><input class='easyui-radio' type='radio' name='isadmin' id='isadmin' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='isadmin' id='isadmin' value='false'/>False</td></tr>
<tr><td>性别:</td><td><input  class='easyui-textbox' type='text' name='gender' id='gender' value='' data-options="required:false"/></td></tr>
<tr><td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td></tr>
<tr><td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><textarea  class='easyui-textarea' type='text' name='description' id='description' data-options="required:false" cols='20' rows='4'></textarea></td></tr>
<tr><td>照片:</td><td><img name='photo' id='photo' width='500px' src='../images/blank.jpg'><br>
<input id="userPhotoFileupload" type="file" name="files[]" data-url="../controller/userController/addUploadUserPhoto"><br></td></tr>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateUser()">编辑</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#ffedit').form('clear');">清除</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wupdateUser').window('close')">取消</a>
</div>
</div>
<div class="easyui-window" title="查看用户" id="wviewUser" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:800px;height:600px">
<div style="padding:10px 60px 20px 60px">
<form id="ffview" method="post">
<input  type='hidden' name='id' id='id' value=''/>
<table cellpadding="5">
<tr><td>用户名:</td><td><input  class='easyui-textbox' type='text' name='userName' id='userName' value='' data-options="required:false"/></td></tr>
<tr><td>名字:</td><td><input  class='easyui-textbox' type='text' name='firstName' id='firstName' value='' data-options="required:false"/></td></tr>
<tr><td>姓:</td><td><input  class='easyui-textbox' type='text' name='lastName' id='lastName' value='' data-options="required:false"/></td></tr>
<tr><td>电子邮件:</td><td><input  class='easyui-textbox' type='text' name='email' id='email' value='' data-options="required:false"/></td></tr>
<tr><td>是否管理员:</td><td><input class='easyui-radio' type='radio' name='isadmin' id='isadmin' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='isadmin' id='isadmin' value='false'/>False</td></tr>
<tr><td>性别:</td><td><input  class='easyui-textbox' type='text' name='gender' id='gender' value='' data-options="required:false"/></td></tr>
<tr><td>地址:</td><td><input  class='easyui-textbox' type='text' name='address' id='address' value='' data-options="required:false"/></td></tr>
<tr><td>电话:</td><td><input  class='easyui-textbox' type='text' name='phone' id='phone' value='' data-options="required:false"/></td></tr>
<tr><td>描述:</td><td><textarea  class='easyui-textarea' type='text' name='description' id='description' data-options="required:false" cols='20' rows='4'></textarea></td></tr>
<tr><td>照片:</td><td><img name='photo' id='photo' width='500px' src='../images/blank.jpg'><br>
<tr><td>活跃:</td><td><input class='easyui-radio' type='radio' name='active' id='active' value='true' checked='true'/>True<input type='radio' class='easyui-radio' name='active' id='active' value='false'/>False</td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wviewUser').window('close')">关闭</a>
</div>
</div>
<div class="easyui-window" title="设置密码" id="wchangePassword" data-options="iconCls:'icon-save',modal:true,closed:true" style="width:600px;height:400px">
<div style="padding:10px 60px 20px 60px">
<form id="ffchangePassword" method="post">
<input type="hidden" id="userName" name="userName">
<table cellpadding="5">
		<tr><td>新密码:</td><td><input class='easyui-textbox' type='password' name='password' id='password' value='' data-options="required:true"/></td></tr>
		<tr><td>确认新密码:</td><td><input class='easyui-textbox' type='password' name='confirmPassword' id='confirmPassword' value='' data-options="required:true"/></td></tr>
</table>
</form>
<div style="text-align:center;padding:5px">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="changePasswordUser()">重设密码</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#wchangePassword').window('close')">关闭</a>
</div>
</div>
</body>
<script type="text/javascript">
var params = {};
var pagesize = 10;
var pagenum = 1;
$(function () {
	$('#addUserPhotoFileupload').fileupload({
			autoUpload: true,
			dataType: 'json',
			async: false,
			success: function(data, textStatus) {
			if (data.success == true){
				$("#ff").find("#photo").prop("src","data:image/png;base64,"+data.rows)
			}
			},
			progressall: function (e, data) {
				var progress = parseInt(data.loaded / data.total * 100, 10);
			},
		});
	$('#userPhotoFileupload').fileupload({
			autoUpload: true,
			dataType: 'json',
			async: false,
			success: function(data, textStatus) {
			if (data.success == true){
				$("#ffedit").find("#photo").prop("src","data:image/png;base64,"+data.rows)
			}
			},
			progressall: function (e, data) {
				var progress = parseInt(data.loaded / data.total * 100, 10);
			},
		});
});
var toolbar = [
{
	text:'查看',
	iconCls:'icon-search',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		$("#ffview").find("#id").val(rows[0]["id"]);
		$("#ffview").find("#userName").textbox("setValue",rows[0]["userName"]);
		$("#ffview").find("#firstName").textbox("setValue",rows[0]["firstName"]);
		$("#ffview").find("#lastName").textbox("setValue",rows[0]["lastName"]);
		$("#ffview").find("#email").textbox("setValue",rows[0]["email"]);
		var isadminCheckboxs = $("#ffview").find("input[name='isadmin']");
		for (var i=0;i<isadminCheckboxs.length;i++){
			if (isadminCheckboxs.get(i).value == ""+rows[0]["isadmin"]) isadminCheckboxs.get(i).checked=true;
		}
		$("#ffview").find("#gender").textbox("setValue",rows[0]["gender"]);
		$("#ffview").find("#address").textbox("setValue",rows[0]["address"]);
		$("#ffview").find("#phone").textbox("setValue",rows[0]["phone"]);
		$("#ffview").find("#description").val(rows[0]["description"]);
		if (!isBlank(rows[0]["photo"]))	{
			$("#ffview").find("#photo").prop("src","data:image/png;base64,"+rows[0]["photo"]);
		}else{
			$("#ffview").find("#photo").prop("src","../images/blank.jpg");
		}
		var checkboxs = $("#ffview").find("input[name='active']");
		for (var i=0;i<checkboxs.length;i++){
			if (checkboxs.get(i).value == ""+rows[0]["active"]) checkboxs.get(i).checked=true;
		}
		$('#wviewUser').window('open');
	}
}
,
{
	text:'新增',
	iconCls:'icon-add',
	handler:function(){
		$('#waddUser').window('open');
	}
}
,
{
	text:'设置密码',
	iconCls:'icon-reload',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		$("#ffchangePassword").find("#userName").val(rows[0]["userName"]);
		$('#wchangePassword').window('open');
	}
}
,
{
	text:'编辑',
	iconCls:'icon-edit',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		$("#ffedit").find("#id").val(rows[0]["id"]);
		$("#ffedit").find("#userName").textbox("setValue",rows[0]["userName"]);
		$("#ffedit").find("#firstName").textbox("setValue",rows[0]["firstName"]);
		$("#ffedit").find("#lastName").textbox("setValue",rows[0]["lastName"]);
		$("#ffedit").find("#email").textbox("setValue",rows[0]["email"]);
		var isadminCheckboxs = $("#ffedit").find("input[name='isadmin']");
		for (var i=0;i<isadminCheckboxs.length;i++){
			if (isadminCheckboxs.get(i).value == ""+rows[0]["isadmin"]) isadminCheckboxs.get(i).checked=true;
		}
		$("#ffedit").find("#password").textbox("setValue",rows[0]["password"]);
		$("#ffedit").find("#gender").textbox("setValue",rows[0]["gender"]);
		$("#ffedit").find("#salt").textbox("setValue",rows[0]["salt"]);
		$("#ffedit").find("#loginFailure").textbox("setValue",rows[0]["loginFailure"]);
		$("#ffedit").find("#address").textbox("setValue",rows[0]["address"]);
		$("#ffedit").find("#phone").textbox("setValue",rows[0]["phone"]);
		$("#ffedit").find("#description").val(rows[0]["description"]);
		if (!isBlank(rows[0]["photo"]))	{
			$("#ffedit").find("#photo").prop("src","data:image/png;base64,"+rows[0]["photo"]);
		}else{
			$("#ffedit").find("#photo").prop("src","../images/blank.jpg");
		}
		var checkboxs = $("#ffedit").find("input[name='active']");
		for (var i=0;i<checkboxs.length;i++){
			if (checkboxs.get(i).value == ""+rows[0]["active"]) checkboxs.get(i).checked=true;
		}
		$('#wupdateUser').window('open');
	}
}
,
{
	text:'软删除',
	iconCls:'icon-remove',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		var id = rows[0]["id"];
		softDeleteUser(id);
	}
}
,
{
	text:'激活',
	iconCls:'icon-tip',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		var id = rows[0]["id"];
		activateUser(id);
	}
}
,
{
	text:'克隆',
	iconCls:'icon-add',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		var id = rows[0]["id"];
		cloneUser(id);
	}
}
,
{
	text:'删除',
	iconCls:'icon-remove',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if ($.messager.confirm("警告","确认要删除选定记录吗？", function(data){
			if (data){
				if (rows.length > 1) {
					$.messager.alert("警告","请选定一条记录！","warning");
					return;
				}
				var id = rows[0]["id"];
				deleteUser(id);
			}
		}));
}
}
,
{
	text:'切换',
	iconCls:'icon-cut',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		var id = rows[0]["id"];
		toggleUser(id);
	}
}
,
{
	text:'留一切换',
	iconCls:'icon-cut',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		if (rows.length > 1) {
			$.messager.alert("警告","请选定一条记录！","warning");
			return;
		}
		var id = rows[0]["id"];
		toggleOneUser(id);
	}
}
,'-',
{
	text:'批软删除',
	iconCls:'icon-remove',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定记录！","warning");
			return;
		}
		var ids = "";
		for(var i=0;i<rows.length;i++){
			ids += rows[i]["id"];
			if (i < rows.length-1) ids += ",";
		}
		softDeleteAllUsers(ids);
	}
}
,
{
	text:'批激活',
	iconCls:'icon-tip',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定记录！","warning");
			return;
		}
		var ids = "";
		for(var i=0;i<rows.length;i++){
			ids += rows[i]["id"];
			if (i < rows.length-1) ids += ",";
		}
		activateAllUsers(ids);
	}
}
,
{
	text:'批克隆',
	iconCls:'icon-add',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定记录！","warning");
			return;
		}
		var ids = "";
		for(var i=0;i<rows.length;i++){
			ids += rows[i]["id"];
			if (i < rows.length-1) ids += ",";
		}
		cloneAllUsers(ids);
	}
}
,
{
	text:'批删除',
	iconCls:'icon-remove',
	handler:function(){
		var rows = $("#dg").datagrid("getChecked");
		if (rows == undefined || rows == null || rows.length == 0 ){
			$.messager.alert("警告","请选定记录！","warning");
			return;
		}
		if ($.messager.confirm("警告","确认要删除选定记录吗？",function(data){
			if (data){
				var ids = "";
				for(var i=0;i<rows.length;i++){
					ids += rows[i]["id"];
					if (i < rows.length-1) ids += ",";
				}
				deleteAllUsers(ids);
			}
		}));
	}
}
,
{
	text:'Excel导出',
	iconCls:'icon-sum',
	handler:function(){
		window.location.href="../controller/userController/exportUsers";
	}
}
,
{
	text:'PDF导出',
	iconCls:'icon-print',
	handler:function(){
		window.location.href="../controller/userController/exportUsersPDF";
	}
}
];
$(document).ready(function(){
checkAccessUser();
$("#dg").datagrid("load");
});
function clearForm(formId){
$('#'+formId).form('clear');
}
function addUser(){
	if ($("#ff").find("#password").val()!=$("#ff").find("#confirmPassword").val()){
		$.messager.alert("错误","密码不匹配！","error");
		return;
	}
	if ($("#ff").form("validate")) {
		$.ajax({
			type: "post",
			url: "../controller/userController/addUser",
			data: JSON.stringify({
				userName:$("#ff").find("#userName").textbox("getValue"),
				password:hex_sha1($("#ff").find("#password").textbox("getValue")),
			active:parseBoolean($("#ff").find("input[name='active']:checked").val()),
			firstName:$("#ff").find("#firstName").val(),
			lastName:$("#ff").find("#lastName").val(),
			email:$("#ff").find("#email").val(),
			isadmin:parseBoolean($("#ff").find("input[name='isadmin']:checked").val()),
			gender:$("#ff").find("#gender").val(),
			address:$("#ff").find("#address").val(),
			phone:$("#ff").find("#phone").val(),
			description:$("#ff").find("#description").val(),
			photo:$("#ff").find("#photo").val(),
			}),
			dataType: 'json',
			contentType:"application/json;charset=UTF-8",
			success: function(data, textStatus) {
				if (data.success) {
					$('#ff').form('clear');
					$("#ff").find("input[name='active']").get(0).checked = true;
					$("#waddUser").window('close');
					$("#dg").datagrid("load");
					$.messager.alert("信息","注册用户成功！","info");
				} else {
					$.messager.alert("错误",data.error,"error");
				}
				},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function(XMLHttpRequest,textStatus,errorThrown) {
				alert("Error:"+textStatus);
				alert(errorThrown.toString());
			}
		});
	}
}

function updateUser(){
	$.ajax({
		type: "post",
		url: "../controller/userController/updateUser",
		data: JSON.stringify({
			id:parseInt($("#ffedit").find("#id").val()),
			userName:$("#ffedit").find("#userName").val(),
			active:parseBoolean($("#ffedit").find("input[name='active']:checked").val()),
			firstName:$("#ffedit").find("#firstName").val(),
			lastName:$("#ffedit").find("#lastName").val(),
			email:$("#ffedit").find("#email").val(),
			isadmin:parseBoolean($("#ffedit").find("input[name='isadmin']:checked").val()),
			password:$("#ffedit").find("#password").val(),
			gender:$("#ffedit").find("#gender").val(),
			salt:$("#ffedit").find("#salt").val(),
			loginFailure:parseInt($("#ffedit").find("#loginFailure").val()),
			address:$("#ffedit").find("#address").val(),
			phone:$("#ffedit").find("#phone").val(),
			description:$("#ffedit").find("#description").val(),
			photo:$("#ffedit").find("#photo").val(),
		}),
		dataType: 'json',
		contentType:"application/json;charset=UTF-8",
		success: function(data, textStatus) {
			if (data.success){
				$("#wupdateUser").window('close');
				$("#dg").datagrid("load");
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function softDeleteUser(id){
	$.ajax({
		type: "post",
		url: "../controller/userController/softDeleteUser",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function activateUser(id){
	$.ajax({
		type: "post",
		url: "../controller/userController/activateUser",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function cloneUser(id){
	$.ajax({
		type: "post",
		url: "../controller/userController/cloneUser",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function deleteUser(id){
	$.ajax({
		type: "post",
		url: "../controller/userController/deleteUser",
		dataType: 'json',
		data:{"id":id},
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function toggleUser(id){
	$.ajax({
		type: "post",
		url: "../controller/userController/toggleUser",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function toggleOneUser(id){
	$.ajax({
		type: "post",
		url: "../controller/userController/toggleOneUser",
		data: {
			"id":id
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function softDeleteAllUsers(ids){
	$.ajax({
		type: "post",
			url: "../controller/userController/softDeleteAllUsers",
			data: {
				ids:ids
			},
			dataType: 'json',
			success: function(data, textStatus) {
				$("#dg").datagrid("load");
			},
			complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function activateAllUsers(ids){
	$.ajax({
		type: "post",
			url: "../controller/userController/activateAllUsers",
			data: {
				ids:ids
			},
			dataType: 'json',
			success: function(data, textStatus) {
				$("#dg").datagrid("load");
			},
			complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function cloneAllUsers(ids){
	$.ajax({
		type: "post",
			url: "../controller/userController/cloneAllUsers",
			data: {
				ids:ids
			},
			dataType: 'json',
			success: function(data, textStatus) {
				$("#dg").datagrid("load");
			},
			complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function deleteAllUsers(ids){
	$.ajax({
		type: "post",
		url: "../controller/userController/deleteAllUsers",
		data: {
			ids:ids
		},
		dataType: 'json',
		success: function(data, textStatus) {
			$("#dg").datagrid("load");
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function searchUsersByFieldsByPage(){
	params = {
		userName:$("#ffsearch").find("#userName").val(),
		active:parseBoolean($("#ffsearch").find("#active").val()),
		firstName:$("#ffsearch").find("#firstName").val(),
		lastName:$("#ffsearch").find("#lastName").val(),
		email:$("#ffsearch").find("#email").val(),
		isadmin:parseBoolean($("#ffsearch").find("#isadmin").val()),
		password:$("#ffsearch").find("#password").val(),
		gender:$("#ffsearch").find("#gender").val(),
		salt:$("#ffsearch").find("#salt").val(),
		loginFailure:$("#ffsearch").find("#loginFailure").val(),
		address:$("#ffsearch").find("#address").val(),
		phone:$("#ffsearch").find("#phone").val(),
		description:$("#ffsearch").find("#description").val(),
	};
	$("#dg").datagrid({queryParams:params});
}

function filterUsersExcel(){
	params = {
		userName:$("#ffsearch").find("#userName").val(),
		active:parseBoolean($("#ffsearch").find("#active").val()),
		firstName:$("#ffsearch").find("#firstName").val(),
		lastName:$("#ffsearch").find("#lastName").val(),
		email:$("#ffsearch").find("#email").val(),
		isadmin:parseBoolean($("#ffsearch").find("#isadmin").val()),
		password:$("#ffsearch").find("#password").val(),
		gender:$("#ffsearch").find("#gender").val(),
		salt:$("#ffsearch").find("#salt").val(),
		loginFailure:$("#ffsearch").find("#loginFailure").val(),
		address:$("#ffsearch").find("#address").val(),
		phone:$("#ffsearch").find("#phone").val(),
		description:$("#ffsearch").find("#description").val(),
	};
	var params0 = $.param(params);
	document.location.href = "../controller/userController/filterUsersExcel?" + params0;
}

function filterUsersPDF(){
	params = {
		userName:$("#ffsearch").find("#userName").val(),
		active:parseBoolean($("#ffsearch").find("#active").val()),
		firstName:$("#ffsearch").find("#firstName").val(),
		lastName:$("#ffsearch").find("#lastName").val(),
		email:$("#ffsearch").find("#email").val(),
		isadmin:parseBoolean($("#ffsearch").find("#isadmin").val()),
		password:$("#ffsearch").find("#password").val(),
		gender:$("#ffsearch").find("#gender").val(),
		salt:$("#ffsearch").find("#salt").val(),
		loginFailure:$("#ffsearch").find("#loginFailure").val(),
		address:$("#ffsearch").find("#address").val(),
		phone:$("#ffsearch").find("#phone").val(),
		description:$("#ffsearch").find("#description").val(),
	};
	var params0 = $.param(params);
	document.location.href = "../controller/userController/filterUsersPDF?" + params0;
}

function checkAccessUser(){
	$.ajax({
		type: "get",
		url: "../controller/userController/checkAccessUser",
		dataType: 'json',
		success: function(data, textStatus) {
			if (!data.success && data.noAuth){
				window.location.href="../login/noauth.html"
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function changePasswordUser(){
	var userName = $("#ffchangePassword").find("#userName").val();
	var password = $("#ffchangePassword").find("#password").val();
	var confirmPassword = $("#ffchangePassword").find("#confirmPassword").val();
	if (isBlank(password)||isBlank(confirmPassword)){
		$.messager.alert("错误","新密码不可为空！","error");
		return;
	}
	if (password!=confirmPassword){
		$.messager.alert("错误","新密码不匹配！","error");
		return;
	}
	$.ajax({
		type: "post",
		url: "../controller/userController/changePasswordUser",
		data: {
			userName:userName,
			password:hex_sha1(password),
		},
		dataType: 'json',
		success: function(data, textStatus) {
			if (data.success) {
				$("#wchangePassword").window("close");
				$.messager.alert("成功","成功修改密码！","info");
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function parseBoolean(val){
	if (val == undefined|| val == null) return false;
	var isInt = /^(-}+)?\d+$/.test(val);
	if (isInt&& val == "0") return false;
	else if (isInt&& val == "1") return true;
	else if (val.toLowerCase() == "false") return false;
	else if (val.toLowerCase() == "true") return true;
	else if (val.toLowerCase() == "f") return false;
	else if (val.toLowerCase() == "t") return true;
	else if (val.toLowerCase() == "n") return false;
	else if (val.toLowerCase() == "y") return true;
	else if (val.toLowerCase() == "no") return false;
	else if (val.toLowerCase() == "yes") return true;
	else return "";
}

function parseBooleanInt(val){
	var b = parseBoolean(val);
	if (b==undefined||b==null) return 0;
	else if (b==true) return 1;
	else return 0;
}

function parseIntNeg(val){
	if (isBlank(val) || parseInt(val) <= 0) return -1;
	else return parseInt(val);
}

function isBlank(val){
	if (val == undefined|| val == null || val == "" || val== "0" || val == 0) return true;
	else return false;
}

function checkRadioBoxValue(control,field,fieldvalue){
	var checkboxs = $("#"+control).find("input[name='"+field+"']");
	for (var i=0;i<checkboxs.length;i++){
		if (checkboxs.get(i).value == ""+fieldvalue) checkboxs.get(i).checked=true;
	}
}

function toggleBtnShow(index){
	$('#button-bar a').css('display','none');
	$('#button-bar a:nth-child('+(index)+')').css('display','block');
}

function showUserPhotoImage(value,row,index){
	if(row.photo){
		return "<img style='height:50px;' border='1' src='data:image/png;base64,"+row.photo+"'/>";
	} else {
		return "<img style='height:50px;' border='1' src='../images/blank.jpg'/>";
	}
}

function showUserPhotoImage(value,row,index){
	if(row.photo){
		return "<img style='height:50px;' border='1' src='data:image/png;base64,"+row.photo+"'/>";
	} else {
		return "<img style='height:50px;' border='1' src='../images/blank.jpg'/>";
	}
}

</script>
</html>
